package coreEngine;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Calendar;

import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.Timer;
import javax.swing.WindowConstants;

import main.SatelliteTracker;



public class Clock {

	private SatelliteTracker st;

	public Clock(final SatelliteTracker st) {

		this.st = st;
		
		Timer t1 = new Timer(1000, new ActionListener() {
			public void actionPerformed(ActionEvent e) {

				//System.out.println(getTime());
				st.updateClock(getTime());
			}
		});
		t1.start();
	}

	String stringTime;
	int hour, minute, second;

	String correctionHour = "";
	String correctionMinute = "";
	String correctionSecond = "";

	public void setStringTime(String xyz) {
		this.stringTime = xyz;
	}
	
	public String writeTime(){
		
		return getTime();
	}

	public int findMinimumBetweenTwoNumbers(int a, int b) {
		return (a <= b) ? a : b;
	}



	public String getTime() {

		Calendar now = Calendar.getInstance();
		hour = now.get(Calendar.HOUR_OF_DAY);
		minute = now.get(Calendar.MINUTE);
		second = now.get(Calendar.SECOND);

		if (hour < 10) {
			this.correctionHour = "0";
		}
		if (hour >= 10) {
			this.correctionHour = "";
		}

		if (minute < 10) {
			this.correctionMinute = "0";
		}
		if (minute >= 10) {
			this.correctionMinute = "";
		}

		if (second < 10) {
			this.correctionSecond = "0";
		}
		if (second >= 10) {
			this.correctionSecond = "";
		}
		return correctionHour + hour + ":" + correctionMinute+ minute + ":" + correctionSecond + second;


	}
}
